﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Microsoft.Practices.Unity;
using ContestMeter.Common;
using ContestMeter.Participants.UI.Properties;

namespace ContestMeter.Participants.UI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public IUnityContainer RootContainer { get; private set; }

        protected override void OnStartup(StartupEventArgs e)
        {
            try
            {
                RootContainer = new UnityContainer();
                var fs = new LocalFileSystem();
                var configuration = Configuration.Load(fs, Settings.Default.TestsFolder, Settings.Default.SolutionFolder);

                RootContainer.RegisterInstance<IConfiguration>(configuration,
                    new ContainerControlledLifetimeManager());
                RootContainer.RegisterInstance<IFileSystem>(fs,
                    new ContainerControlledLifetimeManager());

                MainWindow = RootContainer.Resolve<MainViewModel>().View;
                MainWindow.Show();
                base.OnStartup(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
